"""
个人资料类
"""
import requests

from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


class PersonPage(BasePage):
    # 部门
    department_locator = (By.CSS_SELECTOR, "#department")
    # 地址
    address_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(13) > td:nth-child(2) > textarea")
    # 岗位
    post_locator = (By.CSS_SELECTOR, "#role")
    # 邮箱
    email_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(11) > td:nth-child(2) > input")
    # 手机号
    phone_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(12) > td:nth-child(2) > input")
    # 保存按钮
    save_btn_locator = (By.NAME, "submit")
    # 员工信息修改失败错误信息提示
    person_mistake_tips_locator=(By.CSS_SELECTOR,"#ui-id-5")
    # 员工信息修改成功信息提示
    person_success_tips_locator=(By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > div')

    def choice_department(self,index=1):
        """选择部门"""
        department_element=self.driver.find_element(*self.department_locator)
        select=Select(department_element)
        select.select_by_index(index)

    def choice_post(self,index=1):
        """选择岗位"""
        post_element=self.driver.find_element(*self.post_locator)
        select=Select(post_element)
        select.select_by_index(index)

    def input_email(self,email):
        """输入邮箱"""
        self.driver.find_element(*self.email_locator).send_keys(email)

    def input_phone(self,phone):
        """输入手机号"""
        self.driver.find_element(*self.phone_locator).send_keys(phone)

    def input_address(self,address):
        """输入地址"""
        self.driver.find_element(*self.address_locator).send_keys(address)

    def save_btn(self):
        """保存按钮"""
        self.driver.find_element(*self.save_btn_locator).click()

    def person_mistake_tips(self):
        """错误信息提示"""
        return self.driver.find_element(*self.person_mistake_tips_locator).text

    def persons_success_tips(self):
        """成功信息提示"""
        return self.driver.find_element(*self.person_success_tips_locator).text

    def address_loc(self):
        """地址定位器"""
        self.driver.find_element(*self.address_locator).clear()

    def phone_loc(self):
        """手机定位器"""
        self.driver.find_element(*self.phone_locator).clear()

    def email_loc(self):
        """邮箱定位器"""
        self.driver.find_element(*self.email_locator).clear()

    def test_status(self):
        response = requests.get("http://192.168.0.161/crm/")
        assert response.status_code == 200, f"预期状态码200，实际得到{response.status_code}"
